<?php
    /**
     * Created by PhpStorm.
     * 版权所有: 2019~2022 [ hhygyl ]
     * Date: 2019/8/20-10:50
     * Link: http://luckyadmin.luckyhhy.cn
     * FileName: Link.php
     * Keys: ctrl+alt+L/ctrl+s(代码格式化) ctrl+J(代码提示) ctrl+R(替换)ALT+INSERT(生成代码(如GET,SET方法,构造函数等) , 光标在类中才生效)
     * CTRL+ALT+O (优化导入的类和包 需要配置) SHIFT+F2(高亮错误或警告快速定位错误)
     * CTRL+SHIFT+Z(代码向前) CTRL+SHIFT+/ (块状注释) ctrl+shift+enter(智能完善代码 如if())
     **************************************************************
     *                                                            *
     *   .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.       *
     *    |                     ______                     |      *
     *    |                  .-"      "-.                  |      *
     *    |                 /            \                 |      *
     *    |     _          |              |          _     |      *
     *    |    ( \         |,  .-.  .-.  ,|         / )    |      *
     *    |     > "=._     | )(__/  \__)( |     _.=" <     |      *
     *    |    (_/"=._"=._ |/     /\     \| _.="_.="\_)    |      *
     *    |           "=._"(_     ^^     _)"_.="           |      *
     *    |               "=\__|IIIIII|__/="               |      *
     *    |              _.="| \IIIIII/ |"=._              |      *
     *    |    _     _.="_.="\          /"=._"=._     _    |      *
     *    |   ( \_.="_.="     `--------`     "=._"=._/ )   |      *
     *    |    > _.="                            "=._ <    |      *
     *    |   (_/                                    \_)   |      *
     *    |                                                |      *
     *    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='      *
     *                                                            *
     *                    JUST FIND YOUR BUG !                    *
     **************************************************************
     */


    namespace app\index\controller;


    use service\UtilService;
    use think\Exception;

    class Link extends Base
    {
        protected function _initialize()
        {
            parent::_initialize(); // TODO: Change the autogenerated stub
        }


        /**
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: index
         * @describe:友情链接
         */
        public function index(){
            try{
                $data=db("friendlink")->where("status",1)->order("create_time desc")->select();
            }catch (Exception $exception){

            }
            $this->assign("data",$data);
            return $this->fetch();
        }


        /**
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: addlink
         * @describe:友链申请
         */
        public function addlink(){
            if($this->request->isAjax()){
                $data=$this->request->post();
                $data['type']=1;
                $data['status']=2;
                $data['admin_id']=1;
                $data['ip']=UtilService::getip();
                $data['create_time']=time();
                $data['time_formt']=date("Y-m-d H:i:s",time());
                $res=db("friendlink")->insert($data);
                if($res){
                    $this->success("申请成功！请等待管理员审核通过，已邮件形式发送！注意查收！");
                }else{
                    $this->error("提交失败！请稍后重试！");
                }
            }
            return $this->fetch();
        }

    }